package com.jwsoft.manager.core.gateway.controller.dataStatistics;

import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.dataStatistics.school.SchoolEnrollQueryVO;
import com.jwsoft.manager.common.vo.dataStatistics.school.SchoolEnrollVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolQueryVO;
import com.jwsoft.manager.core.integration.dataStatistics.SchoolDataIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 学校统计相关网关
 *
 * @author wangtao
 * @since 2022-11-24
 */
@Slf4j
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "学校数据统计相关", description = "学校数据统计相关")
public class SchoolDataController {
    @Autowired
    SchoolDataIntegration schoolDataIntegration;

    @PostMapping(value = "/schoolData0001", produces = "application/json;charset=UTF-8")
    @Operation(summary = "获取义务段学校报名统计信息", description = "获取义务段学校报名统计信息")
    public AppResponse<PageInfo<SchoolEnrollVO>> getYwRegistStatistics(
            @RequestBody @Validated SchoolEnrollQueryVO vo) {
        return AppResponse.successData(schoolDataIntegration.getYwRegistStatistics(vo));
    }

    @PostMapping(value = "/schoolData0002", produces = "application/json;charset=UTF-8")
    @Operation(summary = "获取幼儿园报名统计信息", description = "获取幼儿园报名统计信息")
    public AppResponse<PageInfo<SchoolEnrollVO>> getYeyRegistStatistics(
            @RequestBody @Validated SchoolEnrollQueryVO vo) {
        return AppResponse.successData(schoolDataIntegration.getYeyRegistStatistics(vo));
    }

    @RequestMapping(
            value = "/schoolData0003",
            method = {RequestMethod.POST, RequestMethod.GET})
    @Operation(summary = "学校信息导出", description = "学校信息导出")
    @NoSignCrypto
    public void downloadData(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) SchoolEnrollQueryVO vo,
            HttpServletResponse response) {

        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        schoolDataIntegration.downloadData(vo, response);

    }

    @PostMapping(value = "/schoolData0004", produces = "application/json;charset=UTF-8")
    @Operation(summary = "义务段按类别统计报名数据", description = "义务段按类别统计报名数据")
    public AppResponse<PageInfo<SchoolEnrollVO>> getYwRegistStatisticsLb(
            @RequestBody @Validated SchoolEnrollQueryVO vo) {
        return AppResponse.successData(schoolDataIntegration.getYwRegistStatisticsLb(vo));
    }
}
